<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * user-agent 操作
 *
 */
class Ualib {
	var $CI;
	var $user_agent;
	var $default_ua;
	function __construct()
	{
		$this->CI = & get_instance();
		$this->user_agent = $this->CI->input->user_agent();
		$this->default_ua = array('ip', 'network', 'sys_ver', 'user_model', 'client_ver', 'imei', 'client_width', 'unionid');
	}
	
	//将ua信息转换成
	function fetch_array()
	{
		if(!$this->user_agent) return FALSE;
		//以逗号,分隔
		$user_agent_array = explode(',', $this->user_agent);
		if(!is_array($user_agent_array) || count($user_agent_array) ==0 ) return FALSE;
		$result = array();
		foreach ($user_agent_array as $k => $v){
			if(isset($this->default_ua[$k])){
				$result[$this->default_ua[$k]] = $v;
			}else{
				unset($user_agent_array[$k]);
			}
		}
		return $result;
	}

}